package com.apes.fn.crm.ReturnVisit.model;

import com.alibaba.fastjson.annotation.JSONField;
import com.apes.framework.jpa.BaseModel;
import com.apes.framework.jpa.DefaultPersistListener;
import com.apes.framework.jpa.comment.Comment;
import com.apes.framework.jpa.generator.ApesGenerator;
import com.apes.framework.jpa.tuple.date.DateTime;
import com.apes.framework.util.ApesConst;
import com.apes.framework.util.DateUtil;
import com.apes.scm.masterdata.party.model.PartyRole;
import lombok.Getter;
import lombok.Setter;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;
import org.hibernate.annotations.SelectBeforeUpdate;

import javax.persistence.*;
import java.util.Date;

/**
 * 回访量统计日结
 *
 * @author bbyford
 * @create 2020-2-5
 */
@Getter
@Setter
@SelectBeforeUpdate
@DynamicUpdate
@DynamicInsert
@Entity
@EntityListeners(DefaultPersistListener.class)
@Table(name = VisitStatistics.CONST_TABLE_NAME)
public class VisitStatistics extends BaseModel {
    public static final String CONST_TABLE_NAME = "fn_visit_statistics";

    @Id
    @Comment("单号")
    @Column(name = "id", nullable = false, length = 32)
    @ApesGenerator(code =  VisitStatistics.CONST_TABLE_NAME, name = "回访量统计", padding = 8)
    private String id;


    // 上日剩余 今日新增 应回访 待回访 已回访 回访完成 继续回访 终止 已回访率 回访成功率 拨号量

    @Column(name = "qty_rest", nullable = false, columnDefinition = ApesConst.FIELD_QTY_16_4_0)
    @Comment("上日剩余")
    private double qtyRest = 0;


    @Column(name = "qty_add", nullable = false, columnDefinition = ApesConst.FIELD_QTY_16_4_0)
    @Comment("今日新增")
    private double qtyAdd = 0;

    @Column(name = "qty_should_visit", nullable = false, columnDefinition = ApesConst.FIELD_QTY_16_4_0)
    @Comment("应回访")
    private double qtyShouldVisit = 0;

    @Column(name = "qty_wait_visit", nullable = false, columnDefinition = ApesConst.FIELD_QTY_16_4_0)
    @Comment("待回访")
    private double qtyWaitVisit = 0;

    @Column(name = "qty_visited", nullable = false, columnDefinition = ApesConst.FIELD_QTY_16_4_0)
    @Comment("已回访")
    private double qtyVisited = 0;

    @Column(name = "qty_finish", nullable = false, columnDefinition = ApesConst.FIELD_QTY_16_4_0)
    @Comment("回访完成")
    private double qtyFinish = 0;

//    @Column(name = "qty_again", nullable = false, columnDefinition = ApesConst.FIELD_QTY_16_4_0)
//    @Comment("继续回访")
//    private double qtyAgain = 0;

    @Column(name = "qty_end", nullable = false, columnDefinition = ApesConst.FIELD_QTY_16_4_0)
    @Comment("终止")
    private double qtyEnd = 0;

    @Column(name = "qty_call", nullable = false, columnDefinition = ApesConst.FIELD_QTY_16_4_0)
    @Comment("拨号量")
    private double qtyCall = 0;

    @Comment("已回访率")
    @Column(name = "visited_rate", length = 16)
    private String visitedRate;

    @Comment("回访完成率")
    @Column(name = "visited_success_rate", length = 16)
    private String visitedSuccessRate;

    @Comment("人员")
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "visitor_id", referencedColumnName = "id")
    private PartyRole visitor;

    @Transient
    private String visitorName;

    public String getVisitorName(){
        if( visitor == null ) return null;
        return visitor.getName();
    }

    @JSONField(format = DateUtil.SHOW_DATE_FORMAT)
    @Temporal(TemporalType.DATE)
    @Column(name = "insert_date", updatable = false)
    @Comment("写入日期")
    private Date insertDate;

    @Transient
    private String statisticsDate;

}
